﻿using System.Globalization;
using System.Linq;

namespace MediaScraper.Common
{
    public static class CultureHelper
    {
        public static string GetCurrentCultureName()
        {
            return GetThreeLetterCode(CultureInfo.CurrentCulture);
        }

        public static string GetThreeLetterCode(CultureInfo culture)
        {
            return culture.ThreeLetterISOLanguageName;
        }

        public static string GetTwoLetterCode(CultureInfo culture)
        {
            return culture.TwoLetterISOLanguageName;
        }

        public static CultureInfo GetCultureByLanguageName(string languageName)
        {
            return CultureInfo.GetCultures(CultureTypes.AllCultures).FirstOrDefault(c => c.DisplayName == languageName);
        }

        public static string GetThreeLetterCodeByLanguageName(string languageName)
        {
            var culture = GetCultureByLanguageName(languageName);

            if (culture != null)
            {
                return GetThreeLetterCode(culture);
            }
            return string.Empty;
        }
        
        public static string GetTwoLetterCodeByLanguageName(string languageName)
        {
            var culture = GetCultureByLanguageName(languageName);

            if (culture != null)
            {
                return GetTwoLetterCode(culture);
            }
            return string.Empty;
        }
    }
}